/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.manager.promandgst;

import assignment_cp3120.DAO.Factory.DAOFactory;
import assignment_cp3120.ucm.UC2AL;
import assignment_cp3120.ucm.UCPromotionAndGST;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Administrator
 */
public class PromoGSTView extends JPanel{
    private JTextField discountPercentField;
    private JLabel discountLabel;
    
    private JTextField gstField;
    private JLabel gstLabel;
    
    private JButton saveButton;

    private PromoGSTModel model;
    
    public PromoGSTView() {
        model = new PromoGSTModel();
        createView();
    }
    private void createView(){
        discountPercentField = new JTextField("mmmm");
        discountPercentField.setPreferredSize(discountPercentField.getPreferredSize());
        discountPercentField.setText(Integer.toString(DAOFactory.getDAOFactory().getGST_PromoDAO().getPromo()));
        discountLabel = new JLabel("Enter a value to change the discount to:");

        gstField = new JTextField("mmm");
        gstLabel = new JLabel("Enter a value to change the GST to:");
        gstField.setPreferredSize(discountPercentField.getPreferredSize());
        gstField.setText(Integer.toString(DAOFactory.getDAOFactory().getGST_PromoDAO().getGST()));

        saveButton = new JButton("Save Changes");
        saveButton.addActionListener(new UC2AL(new UCPromotionAndGST(this,model)));
        JPanel discountFieldPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JPanel gstPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        
        discountFieldPanel.add(discountLabel);
        discountFieldPanel.add(discountPercentField);        
        discountFieldPanel.add(new JLabel("%"));
        
        gstPanel.add(gstLabel);
        gstPanel.add(gstField);
        gstPanel.add(new JLabel("%"));
        
        JPanel p1=  new JPanel(new FlowLayout(FlowLayout.LEFT));

        p1.add(new JLabel("Customers this discount when they " +
            "purchase multiple tickets on the one flight"));
        add(new JPanel());
        add(p1);
        add(discountFieldPanel);
        add(gstPanel);
        add(saveButton);
    }
    public int getGST() {
        return Integer.parseInt(gstField.getText());
    }
    public int getPromo() {
        return Integer.parseInt(discountPercentField.getText());
    }
    public void clearView() {
        this.removeAll();
        createView();
        repaint();
    }
}
